﻿using S2Cloud.SmartFlow.GrpcHelper;
using System.Collections.Generic;
using System.Data;

namespace S2_Xxxx_XxxNetApi
{
    /// <summary>
    /// 工作流帮助类
    /// </summary>
    public class WorkFlowHelper
    {
        /// <summary>
        /// 激活流程
        /// </summary>
        /// <param name="flowId">流程id</param>
        /// <param name="userId">用户id</param>
        public static dynamic Activate(string flowId, string userId)
        {
            return GrpcClientSingle.S2GrpcClient.flowManager.Activate(flowId, userId);
        }

        /// <summary>
        /// 激活流程节点
        /// </summary>
        /// <param name="flowId">流程id</param>
        /// <param name="nodeCode">流程节点code</param>
        /// <param name="userId">用户id</param>
        /// <param name="approver">	审批人(如何没有可以为空数组)</param>
        /// <param name="cancelNodes">取消的节点的集合(如何没有可以为空数组)</param>
        public static dynamic Activate(string flowId, string nodeCode, string userId, string[] approver, string[] cancelNodes)
        {
            //string[] approver = { "18f923a7-5a5e-426d-94ae-a55ad1a4b239" };
            //string[] cancelNodes = { "Activity2", "Activity1" };
            return GrpcClientSingle.S2GrpcClient.flowManager.ActivateNode(flowId, nodeCode, userId, approver, cancelNodes);
        }

        /// <summary>
        /// 取消流程节点
        /// </summary>
        /// <param name="flowId">流程id</param>
        /// <param name="nodeCode">流程节点code</param>
        /// <param name="userId">用户id</param>
        public static dynamic CancelNode(string flowId, string nodeCode, string userId)
        {
            return GrpcClientSingle.S2GrpcClient.flowManager.CancelNode(flowId, nodeCode, userId);
        }

        /// <summary>
        /// 调整流程节点参与者
        /// </summary>
        /// <param name="flowId">流程id</param>
        /// <param name="nodeCode">流程节点code</param>
        /// <param name="userId">用户id</param>
        /// <param name="approver">	审批人</param>
        public static dynamic AdjustNode(string flowId, string nodeCode, string userId, string[] approver)
        {
            //string[] approver = { "18f923a7-5a5e-426d-94ae-a55ad1a4b239" };
            return GrpcClientSingle.S2GrpcClient.flowManager.AdjustNode(flowId, nodeCode, userId, approver);
        }

        /// <summary>
        /// 修改某个流程的业务数据和流程数据的发起人
        /// </summary>
        /// <param name="tabName">业务表名</param>
        /// <param name="objectId">业务数据ID</param>
        /// <param name="userId">调整用户ID</param>
        /// <returns></returns>
        public static dynamic AdjustBusinessData(string tabName, string objectId, string userId)
        {
            string sql = string.Format("Select * from {0} where ObjectID='{1}'", tabName, objectId);
            DataTable dt = MySqlHelper.GetDataTable(CommandType.Text, sql, null);
            if (dt.HasData()) 
            {
            
            }
            return "";
        }

        /// <summary>
        /// 根据InstanceId和某个节点Code获取所有待办人，节点Code不是必填，如果不填就是获取所有待办人
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="activeCode"></param>
        /// <returns></returns>
        public static dynamic GetHandleUserByInstanceId(string instanceId, string activeCode) 
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 根据InstanceId和某个节点Code获取所有已办人
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="activeCode"></param>
        /// <returns></returns>
        public static dynamic GetDoneUerByInstanceId(string instanceId, string activeCode)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 根据某个流程的某个节点增加一个人或多个人的待办
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="activeCode"></param>
        /// <returns></returns>
        public static dynamic AddHandleUserByInstanceId(string instanceId, string activeCode)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 根据某个流程的某个节点删除一个人或多个人的待办
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="activeCode"></param>
        /// <returns></returns>
        public static dynamic DelHandleUserByInstanceId(string instanceId,string activeCode)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 调整某个流程的当前审批节点到新的节点并指定新的节点审批人
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="activeCode"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static dynamic AdjustActiveNode(string instanceId,string activeCode,string userId)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 获取下一个节点的审批人集合和节点名称
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="activeCode"></param>
        /// <returns></returns>
        public static dynamic GetNextActiveNodeApprovalUser(string instanceId,string activeCode)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 指定某个流程的某个审批节点的审批人集合
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="activeCode"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static dynamic SetActiveNodeApprovalUser(string instanceId,string activeCode,string userId)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 一个流程分发成多个子流程，并删除原流程，并将节点指到指定的审批节点，返回InstanceId
        /// </summary>
        /// <param name="formData"></param>
        /// <param name="userId"></param>
        /// <param name="activeCode"></param>
        /// <returns></returns>
        public static dynamic CreateNewInstance(Dictionary<string, string> formData, string userId, string activeCode)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 一个流程分发成多个子流程，并保留原流程，并将节点指到指定的审批节点，返回InstanceId，业务数据的ParentObjectID指向原流程的ObjectID
        /// </summary>
        /// <param name="formData"></param>
        /// <param name="userId"></param>
        /// <param name="activeCode"></param>
        /// <returns></returns>
        public static dynamic CreateNewInstanceExtend(Dictionary<string,string> formData,string userId,string activeCode)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 根据流程ID获取所有流程节点名称和Code
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public static dynamic GetAllActiveNodeByInstanceId(string instanceId)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 根据InstanceId获取所有审批意见
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public static dynamic GetApprovalcommentsByInstanceId(string instanceId)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 根据InstanceId和节点Code插入审批意见
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public static dynamic InsertApprovalcomments(string instanceId)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 根据流程ID获取当前流程已办人集合和代办人员集合
        /// </summary>
        /// <param name="instanceId"></param>
        /// <returns></returns>
        public static dynamic GetHandleUserAndDoneUserByInstanceId(string instanceId)
        {
            return new { result = new List<string>() };
        }

        /// <summary>
        /// 根据流程ID和人员Code或Id取消待办
        /// </summary>
        /// <param name="instanceId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public static dynamic CancelHandleByInstanceIdAndUserId(string instanceId,string userId)
        {
            return true;
        }
    }
}
